package sfy.dao;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
	private static String url;
	private static String driver;
	private static String user;
	private static String password;
	private static Connection conn;

	static {
		Properties properties = new Properties();
		InputStream in = DBUtil.class.getResourceAsStream("db.properties");
		try {
			properties.load(in);
			url = properties.getProperty("url");
			driver = properties.getProperty("driver");
			user = properties.getProperty("user");
			password = properties.getProperty("password");
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, password);
			OutputStream out=new FileOutputStream("db.properties");
			properties.setProperty("url", "111");
			System.out.println(properties.getProperty("url")+"5555555555555555");

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("文件读取失败!");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("驱动加载失败!");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("数据库连接失败!");
		}

	}

	public static Connection getConn() {
		return conn;
	}

}
